<?php
require 'spl.php';

function required_valid($p_1, $p_2, $p_3, $p_4) {
    //初始化

    $Parameters = new \liyuze\Parameters\Parameters();
    //配置参数和验证规则
    $Parameters->config([
        'p_1' => [$p_1, 'required' ],
        'p_2' => [$p_2, 'required' ],
        'p_3' => [$p_3, 'required' ],
        //自定义为空验证规则
        'p_4' => [$p_4, ['required', 'isEmpty' => function($value) {
            return $value === null;
        }]],
        //下面是等效设置。
        //'p_4' => [$p_4, ['required', 'isEmpty' => [null]]]
    ], true);

    //验证
    $Parameters->validate();

    return $Parameters->getErrors();
}

function test()
{
    $p_1 = null;
    $p_2 = '';
    $p_3 = [];
    $p_4 = '';
    $r = required_valid($p_1, $p_2, $p_3, $p_4);
    return json_encode($r, 256);
}

var_dump(
    test()
);

